<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="common/layout">
<head>
    <title>编辑台桌</title>
    <script th:inline="javascript">
        $(function(){
            setTimeout(function(){
                $("#diningtableForm").ajaxForm({
                            callback: function(data) {
                                if (data.valid) {
                                    self.location.href = data.url || '/';
                                } else {
                                    alert(data.errorMsg);
                                }
                            },
                            validate: function(data) {
                                var table_name = $("#table_name").val();
                                if(table_name.length==0){
                                    alert("台桌名不能为空");
                                    return false;
                                }
                                if(table_name.length>10){
                                    alert("台桌名最大长度为10");
                                    return false;
                                }

                                var reg = /^\d+$/;
                                var discount = $("#seating_id").val();
                                if(reg.test(discount)==false){
                                    alert("请输入正确的座位数！");
                                    $("#seating_id").val("");
                                    return false;
                                }else if(discount>10){
                                    alert("座位数最大为10");
                                    return false;
                                }
                                return true;
                            }
                        }
                )
            },200);
        });
        function edit_cancel() {
            self.location.href = '/admin/table';
        };
    </script>
</head>
<body>
<section layout:fragment="top_menu" style="text-align: left;padding-left: 20px">
    <span style="font-size: 20px">修改台桌</span>
</section>

<section layout:fragment="content">
    <form id="diningtableForm" class="form" th:action="@{/admin/table/{id}(id=${table.id})}" th:object="${table}" th:method="PUT">
        <table>
            <tbody>
            <tr>
                <td style="text-align: right">
                    桌名
                </td>
                <td>
                    <input id="table_name" th:field="*{name}"  type="text">
                </td>
            </tr>
            <tr>
                <td style="text-align: right">
                    座位数
                </td>
                <td>
                    <input id="seating_id" th:field="*{seating}"  type="text" >
                </td>
            </tr>
            <tr>
                <td style="text-align: right">
                    责任人
                </td>
                <td>
                    <select id="waiter_id" th:field="*{managerId}" th:value="table!=null? *{manager}: ''" mod="normal">
                        <option th:each="waiter :${waiters}"
                                th:value="${waiter.id}"
                                th:text="${waiter.username}"></option>
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center">
                    <input type="submit" class="new_button_yellow input_submit" value="保存">
                    <input type="button" onclick="javascript:edit_cancel()"  class="new_button_yellow" value="取消">
                </td>
            </tr>
            </tbody>
        </table>
    </form>
</section>

</body>

</html>